﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using TinyPMS_Jerusalem.Models.Validation;

namespace TinyPMS_Jerusalem.Models.DBModel
{
    #region Validation
    [MetadataType(typeof(PropertyMetadata))]
    public partial class Property
    {
        [Bind(Exclude = "BorrowerName,RenewCount,Status")]
        public class PropertyMetadata
        {
            [DisplayName("物品编号")]
            [Required(ErrorMessage = "请填入物品的ID")]
            [StringLength(256, ErrorMessage = "物品的ID超出最大长度(256个字符)")]
            //[PropertyIDMustBeUnique(ErrorMessage = "物品的ID必须是唯一的")]  Todo:已近在Controller里做了手动判断,可以考虑废弃这个Attribute
            public string ID { get; set; }

            [DisplayName("物品名称")]
            [Required(ErrorMessage = "请填入物品的名称")]
            [StringLength(256, ErrorMessage = "物品的名称超出最大长度(256个字符)")]
            public string Name { get; set; }

            [DisplayName("物品简介")]
            [Required(ErrorMessage = "请填入物品的简介")]
            public string Introduction { get; set; }

            //[BoolRequired(ErrorMessage = "请输入True或False")]  // Todo:做一个下拉框
            [DisplayName("是否提供借出")]
            [Required(ErrorMessage = "请选择物品是否提供借出")]
            public bool Available { get; set; }

            [DisplayName("是否已借出")]
            [ScaffoldColumn(false)]
            public bool Status { get; set; }

            [DisplayName("物品分类")]
            [Required(ErrorMessage = "请填入物品的分类")]
            [CategoryMustExist(ErrorMessage = "分类不存在")]
            [StringLength(256, ErrorMessage = "物品的分类超出最大长度(256个字符)")]
            public string Category { get; set; }

            [DisplayName("物品分类标签")]
            [Required(ErrorMessage = "请填入物品的分类标签")]
            [StringLength(256, ErrorMessage = "物品的分类标签超出最大长度(256个字符)")]
            public string Tags { get; set; }

            [DisplayName("借出者姓名")]
            [ScaffoldColumn(false)]
            public string BorrowerName { get; set; }

            [DisplayName("物品最大续借次数")]
            [Required(ErrorMessage = "请填入物品的最大续借次数，0表示物品无法续借")]
            public int MaxRenewCount { get; set; }

            [DisplayName("已续借次数")]
            [ScaffoldColumn(false)]
            public int RenewCount { get; set; }

            [DisplayName("物品标记价格")]
            [Required(ErrorMessage = "请填入物品的标记价值")]
            public int Price { get; set; }

            [DisplayName("物品一次借出最长时间（天）")]
            [Required(ErrorMessage = "请填入物品的最大借出时间（以天计），0表示物品无法借出")]
            [Range(0,365,ErrorMessage="时间间隔超出范围，请填入合理的时间价格")]
            public int Duration { get; set; }
        }
    }
    #endregion
}